import axios from "axios";


const instance = axios.create({
    timeout: 3000,
})

instance.interceptors.request.use(
    (config) => {
        let type = config.url.split("/")[1]
        // 根据路由判断,后台地址是哪个
        if (type === 'rk') {
            config.baseURL = "http://192.168.3.6:8080"
        } else {
            config.baseURL = "http://" + localStorage.getItem("#server")
        }
        return config
    }, (error) => {
        Promise.reject(error)
    }
)

instance.interceptors.response.use(
    (res) => {
        if (res.data && res.data.code == 200) {
            return res.data
        } else if (res.data && res.data.code == 500) {
            return new Error("获取数据失败，请联系管理人员")
        }
    },
    (error) => {
        return Promise.reject(error)
    }
)

export default instance